<?php if((arg(1) == 'edit'|| arg(1) == 'add') && (!empty($_GET['farmer_id']))) {
    echo get_template_header_info($form['#farmer']);
}?>
<?php
if(isset($_GET['addr_id'])&& !empty($_GET['addr_id'])) {
    echo get_template_header_info($_GET['addr_id'], 'village');
}
?>
<style>
    .form-type-managed-file{border:0px;}
</style>
<div class="hp-tab-newprd">
    <?php if(!empty($_GET['farmer_id'])){?>
        <img style="margin-left: 75px;" src="<?php echo base_path()?>sites/all/themes/tweme/images/images/farmer.png"/>
    <?php }else if(!empty($_GET['addr_id'])){ ?>
        <img style="margin-left: 75px;" src="<?php echo base_path()?>sites/all/themes/tweme/images/images/village.png"/>
    <?php }?>
    <ul class="j-sw-nav">
    <?php if( arg(1)=="add"&&empty($_GET['farmer_id']) && empty($_GET['addr_id'])) { ?>
        <li class="newprd-s1 tab-li"><a href="<?php echo base_path();?>fertilizer_case/list">查看</a></li>
        <?php if(user_access('add fertilizer_case')){?>
        <li class="newprd-s2 tab-li on "><a href="<?php echo base_path();?>fertilizer_case/add">添加</a></li>
        <?php }?>
    <?php  }elseif((arg(1) == 'add' && !empty($_GET['farmer_id']))|| (arg(1) == "edit" && !empty($_GET['farmer_id']))) {?>
        <?php echo get_tab($form['#farmer'],'fertilizer'); ?>
    <?php  }elseif(arg(1) == 'edit' && empty($_GET['farmer_id'])&& empty($_GET['addr_id'])) {?>
        <li class="newprd-s1 tab-li"><a href="<?php echo base_path();?>fertilizer_case/list">查看</a></li>
        <?php if(user_access('add fertilizer_case')){?>
        <li class="newprd-s2 tab-li"><a href="<?php echo base_path();?>fertilizer_case/add">添加</a></li>
        <?php }?>
        <li class="newprd-s3 tab-li on"><a href="javascript:void(0)">修改</a></li>
    <?php  }elseif((arg(1) == 'add' && !empty($_GET['addr_id'])) || (arg(1) == 'edit' && !empty($_GET['addr_id']))) {?>
        <?php echo get_tab($_GET['addr_id'],'fertilizer_case','village'); ?>
    <?php }?>
    </ul>
    <div class="table-div">
        <?php if( empty($_GET['farmer_id'])) { ?>
            <div class="small-input address-search">
                <div class="form-label"><span class="required">*</span>农户:</div>
                <?php print render($form['farmer_name']);
                if(empty($form['#fertilizer_case_id'])){
                    print render($form['select_farmer_button']);
                }
                ?>
        </div>
        <?php  } ?>
        <div class="small-select max-big-input column" style="clear:both">
            <div class="form-label">专项活动:</div><?php print render($form['special_activities']); ?>
        </div>
        <div class="small-select column" style="clear:both">
            <div class="small-input address-search"><div class="form-label"><span class="required">*</span>农作物:</div><?php print render($form['plant']); ?>
            <input type="button" value="继续添加施肥信息" class="btn btn-primary"  style="width:150px;" id='add-fertilizer-info' data-toggle="modal" data-target="#fertilizerCaseExtraModal"></div>
            <div style="clear:both"></div>
        </div>

<!--        <div style="display: none">-->
        <div class="form-label">上传图片:</div>
<!--        <div class="fertilization-div add-fertilization-div file_upload file_upload1"-->
<!--             id='add-fertilizer-info' style="width: 150px; margin: 15px">-->
<!--            <div class="fertilization-title"><span style="font-weight: bold">点击上传图片</span></div>-->
<!--            --><?php //if(isset($form['files']['#value']['file_id1'])){?>
<!--                <span class="add-fertilization" style="margin: 0px;"><img src="--><?php //print file_create_url($form['files']['#value']['file_id1']->uri);?><!--" style=" width: 148px;height: 95px; margin-top: -10px;margin-left: 1px;"></span>-->
<!--            --><?php //}else{?>
<!--                <span class="add-fertilization" style="margin-left: 30px;">+</span>-->
<!--            --><?php //}?>
<!--        </div>-->
            <div class="file_upload file_upload1" id="file_upload" style="width: 40%;float: left; margin-right: 10px;  border: 1px solid #ccc;"><?php print render($form['file_upload1']);?></div>
<!--    </div>-->
<!--        <div class="fertilization-div add-fertilization-div file_upload file_upload2"-->
<!--             id='add-fertilizer-info' style="width: 150px; margin: 15px">-->
<!--            <div class="fertilization-title"><span style="font-weight: bold">点击上传图片</span></div>-->
<!--            --><?php //if(isset($form['files']['#value']['file_id2'])){?>
<!--                <span class="add-fertilization" style="margin: 0px;"><img src="--><?php //print file_create_url($form['files']['#value']['file_id2']->uri);?><!--" style=" width: 148px;height: 95px; margin-top: -10px;margin-left: 1px;"></span>-->
<!--            --><?php //}else{?>
<!--            <span class="add-fertilization" style="margin-left: 30px;">+</span>-->
<!--            --><?php //}?>
<!--        </div>-->
        <div class="file_upload file_upload2" style="width: 40%;float: left; margin-right: 10px;  border: 1px solid #ccc;"><?php print render($form['file_upload2']);?></div>
<!--        <div class="fertilization-div add-fertilization-div file_upload file_upload3"-->
<!--             id='add-fertilizer-info' style="width: 150px; margin: 15px">-->
<!--            <div class="fertilization-title"><span style="font-weight: bold">点击上传图片</span></div>-->
<!--            --><?php //if(isset($form['files']['#value']['file_id3'])){?>
<!--                <span class="add-fertilization" style="margin: 0px;"><img src="--><?php //print file_create_url($form['files']['#value']['file_id3']->uri);?><!--" style=" width: 148px;height: 95px; margin-top: -10px;margin-left: 1px;"></span>-->
<!--            --><?php //}else{?>
<!--            <span class="add-fertilization" style="margin-left: 30px;">+</span>-->
<!--            --><?php //}?>
<!--        </div>-->
        <div class="form-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
        <div class="file_upload file_upload3" style="width: 40%;float: left; margin-right: 10px;margin-top:20px;  border: 1px solid #ccc;"><?php print render($form['file_upload3']);?></div>
<!--        <div class="fertilization-div add-fertilization-div file_upload file_upload4"-->
<!--             id='add-fertilizer-info' style="width: 150px; margin: 15px">-->
<!--            <div class="fertilization-title"><span style="font-weight: bold">点击上传图片</span></div>-->
<!--            --><?php //if(isset($form['files']['#value']['file_id4'])){?>
<!--                <span class="add-fertilization" style="margin: 0px;"><img src="--><?php //print file_create_url($form['files']['#value']['file_id4']->uri);?><!--" style=" width: 148px;height: 95px; margin-top: -10px;margin-left: 1px;"></span>-->
<!--            --><?php //}else{?>
<!--            <span class="add-fertilization" style="margin-left: 30px;">+</span>-->
<!--            --><?php //}?>
<!--        </div>-->
        <div class="file_upload file_upload4" style="width: 40%;float: left; margin-right: 10px;margin-top:20px;  border: 1px solid #ccc;"><?php print render($form['file_upload4']);?></div>
<!--        <div class="fertilization-div add-fertilization-div file_upload file_upload5"-->
<!--             id='add-fertilizer-info' style="width: 150px; margin: 15px">-->
<!--            <div class="fertilization-title"><span style="font-weight: bold">点击上传图片</span></div>-->
<!--            --><?php //if(isset($form['files']['#value']['file_id5'])){?>
<!--                <span class="add-fertilization" style="margin: 0px;"><img src="--><?php //print file_create_url($form['files']['#value']['file_id5']->uri);?><!--" style=" width: 148px;height: 95px; margin-top: -10px;margin-left: 1px;"></span>-->
<!--            --><?php //}else{?>
<!--            <span class="add-fertilization" style="margin-left: 30px;">+</span>-->
<!--            --><?php //}?>
<!--        </div>-->
        <div style="clear: both"></div>
        <div class="form-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
        <div class="file_upload file_upload5" style="width: 40%;float: left; margin-right: 10px;margin-top:20px;  border: 1px solid #ccc;"><?php print render($form['file_upload5']);?></div>



        <div class="small-select column" style="clear:both;margin-top:70px;">
            <div class="small-input"><div class="form-label">效果描述:</div><div style="margin-left: 11.3em; "><?php print render($form['effect_desc']); ?></div></div>
        </div>
        <div style="display: none;"><?php print render($form['fertilization']);?></div>
        <?php
        $fertilizer_case_id = 0;
        foreach( $form['fertilization']['#value'] as $key=>$value){
            $html ='<div class="fertilization-div '.$value->id.'"><div class="fertilization-title">'.$value->type;
            $html .= '<span class="fertilization-delete" onclick="delete_fertilizer(\'fertilizer_case_extra\',\''.$value->id.'\')">-</span></div>';
            $html .= '<ul><li>肥料名称:'.$value->variety_name.$value->proportion.$value->SM."</li>";
            $html .= '<li>用量(千克/亩):'.$value->fertilizer_quantity."</li>";
            $html .= '<li>施肥日期:'.$value->fertilization_date."</li>";
            $html .= '<li>施肥方法:'.$value->fertilization_method."</li></ul></div>";
            $fertilizer_case_id = $value->fertilizer_case_id;
            print render($html);
        }
        ?>
        <div class="fertilization-div add-fertilization-div fertilization-add-div"
             id='add-fertilizer-info'
             data-toggle="modal" data-target="#fertilizerCaseExtraModal" style="border: 0px ; height: 0px; width: 0px">
<!--            <div class="fertilization-title"><span style="font-weight: bold">继续添加施肥信息</span></div>-->
<!--            <span class="add-fertilization">+</span>-->
        </div>
        <div class="add-submit" style="text-align: center"><?php print render($form['submit']); ?></div>
        <?php if(isset($form['#farmer'])&& !empty($form['#farmer'])){?>
            <ul class="table-ul-li">
                <li  style=" padding: 2em 0;float: right; margin-top: -5.8em;margin-right: 24em;"><a href="<?php echo base_path(); ?>fertilizer_case/list?farmer_id=<?php echo $form['#farmer']?>">
                        <input class="btn btn-primary form-submit" type="button"  value="返回">
                    </a></li>
<!--                --><?php //if(user_access('add fertilizer_case')){?>
<!--                    <li>|</li>-->
<!--                    <li><a href="--><?php //echo base_path(); ?><!--fertilizer_case/add?farmer_id=--><?php //echo $form['#farmer']?><!--" --><?php //if(arg(1) == "add" && !empty($_GET['farmer_id'])){?><!--class="selected"--><?php //}?><!--添加</a></li>-->
<!--                --><?php //}
//                if(arg(1) == "edit" && !empty($_GET['farmer_id'])){?>
<!--                    <li>|</li>-->
<!--                    <li class="selected">详情</li>-->
<!--                --><?php //}?>
            </ul>
        <?php }?>
        <?php if(isset($_GET['addr_id'])&& !empty($_GET['addr_id'])){?>
            <ul class="table-ul-li">
                <li style=" padding: 2em 0;float: right; margin-top: -5.8em;margin-right: 24em;"><a href="<?php echo base_path(); ?>fertilizer_case/list?addr_id=<?php echo $_GET['addr_id']?>">
                        <input class="btn btn-primary form-submit" type="button"  value="返回">
                    </a></li>
<!--                --><?php //if(user_access('add fertilizer_case')){?>
<!--                    <li>|</li>-->
<!--                    <li><a href="--><?php //echo base_path(); ?><!--fertilizer_case/add?addr_id=--><?php //echo $_GET['addr_id']?><!--" --><?php //if(arg(1) == "add" && !empty($_GET['addr_id'])){?><!--class="selected"--><?php //}?><!--添加</a></li>-->
<!--                --><?php //}
//                if(arg(1) == "edit" && !empty($_GET['addr_id'])){?>
<!--                    <li>|</li>-->
<!--                    <li class="selected">详情</li>-->
<!--                --><?php //}?>
            </ul>
        <?php }?>
    </div>
</div>

<?php print drupal_render_children($form); ?>
</div></form>
<div>
    <div class="modal fade" id="farmerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close"
                            data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        选择农户
                    </h4>
                </div>
                <div class="modal-body">
                    <?php echo @render(drupal_get_form('farmer_select_list_form',$_GET['addr_id']?$_GET['addr_id']:''));?>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">关闭
                    </button>

                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<div>
    <div class="modal fade" id="fertilizerCaseExtraModal" tabindex="-1" role="dialog" aria-labelledby="fertilizerCaseExtraModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close"
                            data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">
                        施肥推荐
                    </h4>
                </div>
                <div class="modal-body">
                    <?php echo @render(drupal_get_form('fertilizer_extra_edit_form','fertilizer_case_extra','fertilizer_case_id'));?>
                </div>
<!--                <div class="modal-footer">-->
<!--                    <button type="button" class="btn btn-default"-->
<!--                            data-dismiss="modal">关闭-->
<!--                    </button>-->
<!---->
<!--                </div>-->
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</div>
<form><div>